import 'package:base_moudle/index.dart';

import '../../../../new_paltform/define/hy_header.dart';
import '../../../command/project/zs_project_introduce/zs_project_introduce_view.dart';
import '../hy_work_home_logic.dart';
import 'hy_project_progress_cell.dart';

class HyProjectTopCell extends StatelessWidget {
  HyProjectTopCell({Key? key, required this.controller, this.scrollController})
      : super(key: key);

  HyWorkHomeLogic controller;
  ScrollController? scrollController;

  @override
  Widget build(BuildContext context) {
    return Obx(() => ClipRRect(
          borderRadius: BorderRadius.circular(12),
          child: Container(
            color: ColorHex('#3370FF'),
            padding: const EdgeInsets.all(1),
            child: HYContainer(
                backgroundColor: Colors.white,
                alignment: Alignment.center,
                clipBehavior: Clip.hardEdge,
                border: Border.all(color: Colors.transparent),
                borderRadius: const BorderRadius.all(Radius.circular(11)),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    HYContainer(
                      padding: const EdgeInsets.fromLTRB(18, 18, 18, 18),
                      backgroundColor: Colors.white,
                      gradient: LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment.bottomCenter,
                          colors: [ColorHex('#F0F5FD'), ColorHex('#FFFFFF')]),
                      child: Row(
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      ZsText(
                                        '${controller.projectDetail.value.projectName ?? 0}',
                                        fontSize: 16,
                                        color: ColorHex('#0C296E'),
                                        fontWeight: FontWeight.bold,
                                      )
                                          .intoContainer(
                                              padding: const EdgeInsets.only(
                                                  right: 10))
                                          .intoFlexible(flex: 3),
                                      setProjectStatus(
                                          '${controller.projectDetail.value.status ?? 0}')
                                    ],
                                  ).intoFlexible(flex: 3),
                                ],
                              ),
                              ZsText(
                                '${controller.projectDetail.value.projectAddress.isNullOrEmpty() || controller.projectDetail.value.projectAddress == 'null' ? '地址未设置' : controller.projectDetail.value.projectAddress}',
                                top: 10,
                                color: ColorHex('#0C296E'),
                                maxLines: 10,
                                fontWeight: FontWeight.w500,
                              )
                            ],
                          ).intoFlexible(flex: 3),
                          Icon(
                            Icons.arrow_forward_ios_rounded,
                            size: 16,
                            color: zs_black_999,
                          ).intoContainer(
                              padding: const EdgeInsets.only(left: 10))
                        ],
                      ),
                      onTap: () {
                        Get.to(ZsProjectIntroducePage(
                          projectId:
                              controller.projectDetail.value.pid.toString(),
                          companyId: controller.projectDetail.value.companyId
                              .toString(),
                          projectType: controller
                              .projectDetail.value.projectTypeId
                              .toString(),
                          industryNatureOne: controller
                              .projectDetail.value.industryNatureOne
                              .toString(),
                        ));
                      },
                    ),
                    zs_round_radius_contianer(
                        allRadius: 6,
                        margin: const EdgeInsets.only(
                            left: 18, right: 18, top: 12, bottom: 10),
                        padding: const EdgeInsets.fromLTRB(16, 0, 16, 0),
                        color: ColorHex('#F9FAFF'),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            _buildIntroduceItem(
                                '项目类型',
                                controller.projectDetail.value.projectType ??
                                    '未设置'),
                            _buildIntroduceItem(
                                '行业性质',
                                controller.projectDetail.value
                                        .industryNatureOneName ??
                                    '未设置'),
                            _buildIntroduceItem(
                                '项目总监',
                                controller.projectDetail.value.directorName
                                        .isNullOrEmpty()
                                    ? '未设置'
                                    : controller
                                            .projectDetail.value.directorName ??
                                        ''),
                          ],
                        )),
                    if (controller.isOpenMore.value)
                      ProjectProgressCell(controller),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        ZsText(
                          controller.isOpenMore.value ? '点击收起' : '点击展开',
                          color: ColorHex('#187AFF'),
                          fontWeight: FontWeight.w500,
                        ),
                        Icon(
                          controller.isOpenMore.value
                              ? Icons.keyboard_arrow_up_rounded
                              : Icons.keyboard_arrow_down_rounded,
                          size: 16,
                          color: ColorHex('#187AFF'),
                        )
                      ],
                    )
                        .intoContainer(
                            margin: const EdgeInsets.only(top: 8, bottom: 18))
                        .intoGestureDetector(onTap: () {
                      if (controller.isOpenMore.value) {
                        scrollController?.jumpTo(10);
                      }
                      controller.isOpenMore.value =
                          !controller.isOpenMore.value;
                    }),
                  ],
                )),
          ),
        ));
  }

  Widget _buildIntroduceItem(String title, String content) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ZsText(
          title,
          fontSize: 12,
          color: zs_black_999,
        ),
        ZsText(
          content,
          color: zs_black_333,
          fontWeight: FontWeight.bold,
          top: 5,
        ),
      ],
    ).paddingOnly(top: 12, bottom: 12).intoFlexible();
  }

  Widget setProjectStatus(String status) {
    String text = '';
    Color color = ColorHex('#FF7D22');
    Color backgroundColor = ColorHex('#FF7D22', opcity: 0.1);
    switch (status) {
      case '0':
        text = '未生成';
        color = ColorHex('#999999');
        backgroundColor = ColorHex('#E7E7E7');
        break;
      case '1':
        text = '未开始';
        color = ColorHex('#FF7D22');
        backgroundColor = ColorHex('#FFF2E8');
        break;
      case '2':
        text = '进行中';
        color = ColorHex('#187AFF');
        backgroundColor = ColorHex('#D7E2FF');
        break;
      case '3':
        text = '停工中';
        color = ColorHex('#FF5252');
        backgroundColor = ColorHex('#FFE2E2');
        break;
      case '4':
        text = '已暂停';
        color = ColorHex('#D68B0A');
        backgroundColor = ColorHex('#FFF2D7');
        break;
      case '9':
        text = '已完成';
        color = ColorHex('#109622');
        backgroundColor = ColorHex('#D7F4D3');
        break;
    }
    return BoardText(
      text,
      color: color,
      fontSize: 10,
      fontWeight: FontWeight.w600,
      backgroundColor: backgroundColor,
      borderRadius: BorderRadius.circular(2),
      left: 3,
      right: 3,
      top: 2,
      bottom: 2,
    );
  }
}
